 package munyorderweb;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import munyorderweb_DB.Change_Bean;
import munyorderweb_DB.DB_manager;

public class SystemServlet extends HttpServlet
{
	protected void doPost(HttpServletRequest req,
						 HttpServletResponse resp)
			throws ServletException, IOException
	{
		//String zipcode = req.getParameter("category_no");
		//String town = req.getParameter("town");
		Connection con = null;

		try {
			System.out.println("DB1");
			con = DB_manager.getConnection();
System.out.println("DB");
			String sql = "select * from tables";

			PreparedStatement ps = con.prepareStatement(sql);

			//ps.setString(1,"%" + category_no + "%");
			//ps.setString(2,"%" + town + "%");

			ResultSet rs = ps.executeQuery();

			ArrayList<Change_Bean> list = new ArrayList<Change_Bean>();

			Change_Bean change_bean = null;
			while ( rs.next() )
			{
				change_bean = new Change_Bean();
				change_bean.setTable_no(Integer.parseInt(rs.getString("table_no")));
				change_bean.setTable_name(rs.getString("table_name"));
				change_bean.setTable_seats(Integer.parseInt(rs.getString("table_seats")));

/*
				change_bean.setCategory_no(Integer.parseInt(rs.getString("category_no")));
				change_bean.setCategory_name(rs.getString("category_name"));


				change_bean.setMenu_no(Integer.parseInt(rs.getString("menu_no")));
				change_bean.setMenu_name(rs.getString("menu_name"));
				change_bean.setMenu_price(Integer.parseInt(rs.getString("menu_price")));
				change_bean.setOrder_no(Integer.parseInt(rs.getString("order_no")));
				change_bean.setOrder_count(Integer.parseInt(rs.getString("order_count")));
				change_bean.setOrder_delivery(Integer.parseInt(rs.getString("order_delivery")));
				change_bean.setCustomer_no(Integer.parseInt(rs.getString("customer_no")));
				change_bean.setCustomer_total(Integer.parseInt(rs.getString("customer_total")));
				change_bean.setCustomer_person(Integer.parseInt(rs.getString("customer_person")));
				change_bean.setCustomer_member(Integer.parseInt(rs.getString("customer_member")));
				change_bean.setOrder_date(rs.getString("order_date"));*/

				list.add(change_bean);
			}
			req.setAttribute("list", list);

			RequestDispatcher dispatcher = req.getRequestDispatcher("Result.jsp");
			dispatcher.forward(req, resp);
		}

		catch (SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				con.close();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
	}
}